package com.flash.CashAdministration.service.impl;

import com.flash.CashAdministration.entity.FundsAllot;
import com.flash.CashAdministration.mapper.FundsAllotMapper;
import com.flash.CashAdministration.service.FundsAllotService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class FundsAllotServiceImpl implements FundsAllotService {

    @Resource
    FundsAllotMapper fundsAllotMapper;
    @Override
    public List<FundsAllot> selectFundsAllotMap(String businessTime, Integer allotDirection , Integer allotType , int page, int limit) {
        HashMap map = new HashMap();
        map.put("businessTime" , buildWhere(businessTime,allotDirection,allotType));
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        return fundsAllotMapper.selectFundsAllotMap(map);
    }

    @Override
    public int deleteFundsAllot(String fundsAllotId) {
        return fundsAllotMapper.deleteFundsAllot(fundsAllotId);
    }

    @Override
    public int insertFundsAllot(FundsAllot fundsAllot) {
        return fundsAllotMapper.insertFundsAllot(fundsAllot);
    }

    @Override
    public int selectCountFundsAllot() {
        return fundsAllotMapper.selectCountFundsAllot();
    }

    @Override
    public int updateFundsAllot(FundsAllot fundsAllot) {
        return fundsAllotMapper.updateFundsAllot(fundsAllot);
    }

    @Override
    public String selectCash(String accountName) {
        return fundsAllotMapper.selectCash(accountName);
    }

    @Override
    public int deleteBusinessId(String businessId) {
        return fundsAllotMapper.deleteBusinessId(businessId);
    }

    public String buildWhere(String businessTime, Integer allotDirection , Integer allotType ){
        StringBuffer strWhere=new StringBuffer();
        if(businessTime!=null && !businessTime.equals("")){
            System.out.println("a"+businessTime+"s");
            strWhere.append(" and businessTime = '"+businessTime+"'" );
        } if (allotDirection != null) {
            strWhere.append(" and allotDirection =" + allotDirection );
        }  if (allotType != null) {
            strWhere.append(" and allotType = "+ allotType);
        }
        System.out.println(strWhere.toString());
        return strWhere.toString();
    }
}
